/**
 * 
 */
package com.eagle.coders.core.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;

import com.eagle.coders.banking.system.ui.binding.table.bean.BeanValueModel;
import com.eagle.coders.banking.system.ui.binding.table.bean.TableBeanPresentationModel;
import com.eagle.coders.common.form.annotations.type.ActionStatusType;
import com.eagle.coders.common.form.annotations.type.ActionTypes;
import com.eagle.coders.common.form.interfaces.ExecutionRequest;
import com.eagle.coders.common.form.interfaces.ExecutionResponse;
import com.eagle.coders.common.form.interfaces.IExecution;
import com.eagle.coders.core.action.meta.processor.MetaInformation;
import com.eagle.coders.core.action.meta.processor.UsecaseMetaOutActionProcessor;
import com.eagle.coders.core.exceptions.BaseAppException;

/**
 * @author anees
 *
 */
public class DefaultSearchAction implements IExecution {

	@Override
	public ExecutionResponse execute(ExecutionRequest executionRequest)
			throws BaseAppException {
		
		String usecaseId = executionRequest.getUsecaseId();
		ExecutionResponse actionResponse = new ExecutionResponse();
		System.out.println("[DefaultSearchAction] : =========== DefaultSearchAction Started ============ :: "+usecaseId);
		List<?> obj =	executionRequest.getObjectsToProceed();
		Map<String, BeanValueModel> beanValueModel =(Map<String, BeanValueModel>)obj.get(0);
		System.out.println("[DefaultSearchAction] : =========== beanValueModel ============ :: "+beanValueModel);
		
		Set<String> beans =beanValueModel.keySet();
		
		for(String bean : beans){
			//TODO: =============== Have to change the
			BeanValueModel beansModel = beanValueModel.get(bean);
			Map<String, TableBeanPresentationModel> tableFieldModel = beansModel.getTablePropertyValueModelMap();
			Map<String, Object> nonTableFieldModel = beansModel.getNonTablePropertyDataMap();
			System.out.println("[DefaultSearchAction] : =========== nonTableFieldModel ============ :: "+nonTableFieldModel);
		}
		
		MetaInformation metaInformation = new MetaInformation(usecaseId);
		UsecaseMetaOutActionProcessor usecaseMetaOutActionProcessor = metaInformation.getMetaOutActionProcessor();
		SortedMap<Integer, String> tablePropertiesForColsMap = usecaseMetaOutActionProcessor.getTablePropertiesForColsMap();
		
		actionResponse.setSearchTableGeneratorMap(tablePropertiesForColsMap);
		actionResponse.setActionTypes(ActionTypes.SEARCHED_DATA_TABLE_ACTION);
		actionResponse.setActionStatus(ActionStatusType.SUCCESS);

		actionResponse.setObjectList(new ArrayList<Object>());
		return actionResponse;
	}
}
